8696. Grades

 

Petya only gets twos and fives in school. Determine which grade he has more of.

 

Input. One single string contains Petya’s grades. It is known that Petya only receives twos and fives. The grades are written consecutively without spaces, and the total number of grades does not exceed 1000.

 

Output. Print:

·        5 if there are more fives than twos;

·        2 if there are more twos than fives;

·        the equality symbol ‘=’ if the number of twos and fives is equal.

 

Sample input 1

Sample output 1

255222

2

 

 

Sample input 2

Sample output 2

555522

5

 

 

SOLUTION

string

 

Algorithm analysis

Let’s count the number of fives and twos in the string.

·        If there are more fives than twos, print 5.

·        If there are more twos than fives, print 2.

·        If the number of twos and fives is equal, print the equality symbol ‘=’.

 

Algorithm implementation

Read the input string.

 

cin >> s;

 

Compute the number of fives and twos in the string s.

 

fives = twos = 0;

for (i = 0; i < s.size(); i++)

  if (s[i] == '2') twos++; else fives++;

 

Print the answer.

 

if (fives > twos) cout << "5"; else

  if (fives < twos) cout << "2";

  else cout << "=";

cout << endl;

 

Python implementation

Read the input string.

 

s = input()

 

Compute the number of fives and twos in the string s.

 

fives = s.count('5')

twos = s.count('2')

 

Print the answer.

 

if fives > twos:

  print("5")

elif fives < twos:

  print("2")

else:

  print("=")